<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../js/layui/css/layui.css"/>
    <script src="../js/layui/layui.js"></script>
    <script src="../js/jquery/jquery-1.9.1.js"></script>
</head>
<body>
<div class="layui-form">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">职位名称：</label>
            <div class="layui-input-inline">
                <input class="layui-input" id="zhiweitype2" autocomplete="off">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">薪资区间</label>
            <div class="layui-input-inline">
                <input class="layui-input" id="startwage" autocomplete="off">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <input class="layui-input" id="endwage" autocomplete="off">
            </div>
        </div>
        <div class="layui-inline">
            <button class="layui-btn" data-type="reload" onclick="searchs()">搜索</button>
        </div>
    </div>
</div>

<div id="add-main" style="display: none;">
    <!--<form class="layui-form" id="add-form" action="">-->
    <form id="productForm" method="post" class="layui-form">
        <input type="hidden" id="id" name="id">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text"  name="workname" required  lay-verify="required" placeholder="用户名" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">工作地址</label>
            <div class="layui-input-block">
                <input class="layui-input" name="workingplace" placeholder="工作地址">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">邮箱(选填)</label>
            <div class="layui-input-block">
                <input class="layui-input" name="email" placeholder="请输入您的邮箱">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">职位行业</label>
            <div class="layui-input-block">
                <select name="hangye" >

                    <option value="1">java</option>
                    <option value="2">C++</option>
                    <option value="3">PHP</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">薪资</label>
            <div class="layui-input-block">
                <select name="wage" >

                    <option value="13">13</option>
                    <option value="19">19</option>
                    <option value="9">9</option>
                    <option value="15">15</option>

                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="save">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary" id="closeBtn" >重置</button>
            </div>
        </div>
    </form>

</div>

<table id="date" lay-filter="test" ></table>

    <div id="toolbar" style="display: none;">
            <a class="layui-btn layui-btn-warm layui-btn-radius layui-btn-xs" onclick="onAddBtn()">新增</a>
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            <a class="layui-btn layui-btn-xs" lay-event="shoucang">加入收藏</a>
            <!--<button lay-submit lay-filter="shoucang" class="layui-btn">加入收藏</button>-->
    </div>

</body>
<script>
    var table = null;
    layui.use(['table','layer','form','element'], function() {
        table = layui.table;
        var element = layui.element;
        var layer = layui.layer;
        var form = layui.form;
        $(function () {
            var tableList = table.render({
                elem: '#date',
                id:'zhaoPinTableId',
                fit: true,
                cellMinWidth: true, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                url: '../web/querydingyue', //数据接口
                type: "POST",
                loading: false,
                page: true,//开启分页
                limit:6,
                limits:[2,4,6,8,10],
                cols: [
                    [ //表头
                        {type: 'checkbox',title: '全选', fixed: 'left'},
                        {field: 'id', title: 'ID', sort: true, align: 'center', fixed: 'left'},
                        {field: 'workname', title: '职位名称', align: 'center', sort: true},
                        {field: 'workingplace', title: '工作地点', align: 'center', sort: true},
                        {field: 'wage', title: '期望薪资', align: 'center', sort: true,templet:function(data){
                            return  data.wage +"k"

                            }},
                        {field: 'hangye', title: '职位行业', align: 'center', sort: true},
                        {field: 'email', title: '邮箱', align: 'center', sort: true},

                        {field: 'comname', title: '公司名称', align: 'center', sort: true},
                        {fixed: 'right',title: '操作', width: 250, align: 'center', toolbar: '#toolbar'}
                    ]
                ]
            });
        })

        // 监听你的表格
        table.on('tool(test)', function(obj) {
            var data = obj.data;
            var id = data.id

            //  查看ID  ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓  方法
            if (obj.event === 'detail') {
                layer.msg('ID：' + data.id + ' 的查看操作');

                //删除  ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓  方法
            }
            if (obj.event === "del") {
                $.ajax({
                    url: "../web/del2",
                    type: "post",
                    data: {id: data.id},
                    success: function (data) {
                        if (data != "1") {
                            layer.msg(data.id);
                            layer.msg("删除失败", {icon: 5});
                        } else {
                            /*   layer.msg(data.id);*/
                            layer.msg("删除成功", {icon: 6});
                            /*table.reload("date", {})*/
                            table.reload("zhaoPinTableId",{})

                            //关闭弹框
                            layer.close(index);
                       /*     layer.msg("删除成功");*/
                        }
                    }
                })
            }
            if(obj.event==="edit"){
                openEditProductDialog(data.id);
            }if(obj.event==="shoucang"){
                shang(data.id);
            }
        })
    })
    layui.use(['layer', 'form'], function () {
        var layer = layui.layer,
            $ = layui.jquery,
            form = layui.form;

        //提交监听事件
        form.on('submit(save)', function (data) {
            params = data.field;//表单里面所有的值
            //alert(JSON.stringify(params))//
            submit($,params);
            return false;
        })
        var obj = document.getElementById('closeBtn');
        obj.addEventListener('click', function cancel(){
            CloseWin();
        });
    })

    /*layui.use(['form','layer','jquery'], function () {

        // 操作对象
        var form = layui.form;
        var $ = layui.jquery;
        form.on('submit(shoucang)',function (data) { })
    });*/

        /*function shang(id) {
            $.ajax({
                url: '../web/productState',
                data: $("#productForm").serialize(),
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    if (data.code == 0) {
                        alert("成功");
                    } else {
                        layer.msg('已改变');
                    }
                }
            })
            return false;
        }*/

    //上下架
    function shang(id){
        $.post('../web/productState',{id:id},function(data){
            if(data){
                alert("成功");
            }else{
                layer.msg('已改变');
            }
        })
    }

    function submit($,params){
        $.post('../web/adddingyue', params, function (data) {//返回的数据
            /*alert("成功!")*/
            if (data.equals("1")) {
                table.reload("date",{})
                CloseWin();//刷新表格
                location.reload();// 页面刷新
                parent.location.reload();
                layer.close(index);
            }else if(data.equals("2")){
                // parent.location.href='${ctx}/golbal/main';
                layui.alert("失败")
            }else{

                location.reload(); // 页面刷新
                return false
            }
        }, 'json');
    }

    function onAddBtn(){
        //页面层-自定义
        layer.open({
            type: 1,
            title:"新增",
            closeBtn: false,
            shift: 2,
            area: ['850px', '500px'],
            shadeClose: true,
            // btn: ['新增', '取消'],
            // btnAlign: 'c',
            content: $("#add-main"),
            success: function(layero, index){},
            yes:function(){
            }
        });
    }

    function searchs(){
        table.reload("zhaoPinTableId",{
            where: { //设定异步数据接口的额外参数，任意设
                workname: $("#zhiweitype2").val(),//这里获取input的值
                startwage:$("#startwage").val(),
                endwage:$("#endwage").val(),
            }
            ,page: {
                curr: 1 //重新从第 1 页开始
            }
        });
    }

    function  openEditProductDialog(id) {
        layer.open({
            type:2,
            title:'修改商品',
            area: ['700px', '500px'],
            fixed: false, //不固定
            maxmin: true,
            content: '../page/updateyu',
            btn:['保存'],
            success: function(layero,index){
                $.ajax({
                    url:'../web/findyue',
                    data:{id:id},
                    dataType:'json',
                    type:'post',
                    success:function (data) {
                        var iframeWin=window[layero.find("iframe")[0]["name"]];
                        iframeWin.initForm(data);
                    }
                })
            },
            btn1:function (index,layero) {
                var iframeWin=window[layero.find("iframe")[0]["name"]];
                iframeWin.saveProduct();
                layer.close(index);
                table.reload("zhaoPinTableId",{})
            }
        })
    }

</script>
</html>
